<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="format-detection" content="telephone=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-touch-fullscreen" content="yes">
		<meta content="telephone=no,email=no" name="format-detection" />
		<meta name="flexible" content="initial-dpr=2,maximum-dpr=3" />
		<title>羊仓会员专属</title>
		<!--去缓存-->
		<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
		<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
		<META HTTP-EQUIV="Expires" CONTENT="0"><!--end-->
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/zfsuccess.css" />
		<script type="text/javascript" src="../js/jquery.min.js" ></script>
		<script type="text/javascript" src="../js/flexible.js" ></script>
		<script type="text/javascript" src="../js/basePathUtil.js" ></script>
		<!--弹出-->
		<script type="text/javascript" src="../js/layer-mobile/layer.js" ></script>
	</head>
	<body>
		<div class="warp">
			<div class="top">
				<p>支付结果查询中...</p>
			</div>
			<ul class="btn">
				<li class="showTrade" style="visibility: hidden;">

				</li>
				<li class="continue">
					<button style="color:#fff" onclick="continueGo()">继续选货</button>
				</li>
			</ul>
		</div>
	</body>
<script>
	function continueGo() {
		window.location.href= basePath+"v1/user/wx/login";
	}
	function showTrade(token,id) {
		window.location.href=basePath+"res/orderDetail.html?access_token="+token+'&tradeId='+id+"&t="+new Date().getTime();
	}
	var basePath = basePath();
	$(document).ready(function(){
		var tradeId = localStorage.getItem("tradeId");
		var access_token = localStorage.getItem("access_token");
		var ua = window.navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i) != 'micromessenger'){
			layer.open({
				content: '请您转入微信浏览器“我的订单”中查看',
				btn: '好的',
				shadeClose: false,
				end:function () {
					window.location.href= basePath+"v1/user/wx/login";
				}
			});
			return;
		}else{
			if(tradeId!=null && access_token!=null){
				layer.open({
					type: 2,
					content: '支付结果查询中',
					shadeClose: false
				});
				setTimeout(function() {
					$.ajax({
						type:"GET",
						url:basePath+"/v1/trade/api/showTrade?access_token="+access_token,
						dataType : 'json',
						data:{
							tradeId:tradeId
						},
						success:function(data){
							if(data.code==1000) {
								if(data.data.tradeSummary.payStatus=="P"){
									$(".top").html('<p>您的订单已支付成功</p>');
								}else{
									$(".top").html('<p>您的订单未支付成功</p>');
								}
								layer.closeAll();
							}else{
								layer.open({content: data.msg,skin: 'msg',time: 2});
							}
						},
						error:function(data) {
						}
					})
				},5000);
				$(".showTrade").css("visibility","visible");
				$(".showTrade").append('<button onclick="showTrade(\''+access_token+'\',\''+tradeId+'\')">查看订单</button>');
			}else{
				layer.open({
					content: '非法请求',
					skin: 'msg',
					time: 2,
					end: function () {
						window.location.href= basePath+"v1/user/wx/login";
					}
				});
			}
		}
	});
</script>
</html>
